import { Button, Uploader } from '@taroify/core';
import { useState } from 'react';
import { chooseImage } from '@tarojs/taro';

function CustomUploader() {
  const [files, setFiles] = useState<Uploader.File[]>([]);
  function onUpload() {
    chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
    }).then(({ tempFiles }) => {
      setFiles([
        ...files,
        ...tempFiles.map(({ path, type, originalFileObj }) => ({
          type,
          url: path,
          name: originalFileObj?.name,
        })),
      ]);
    });
  }
  return (
    <Uploader multiple value={files} onChange={setFiles} onUpload={onUpload}>
      <Button color="primary">上传文件</Button>
    </Uploader>
  );
}
